import numpy as np
from 深度学习入门基于python的理论与实践.common.functions import softmax, cross_entropy_error
from 深度学习入门基于python的理论与实践.common.gradient import numerical_gradient
class simpleNet:
    def __init__(self):
        self.W = np.random.randn(2,3) #用高斯分布进行初始化
    def predict(self, x):
        return np.dot(x, self.W)
    def loss(self, x, t):
        z = self.predict(x)
        y = softmax(z) #激活函数
        loss = cross_entropy_error(y, t) #损失函数
        return loss

# def f(W):
#     return net.loss(x, t)

if __name__ == '__main__':
    net = simpleNet()
    print(net.W)

    x = np.array([0.6, 0.9])
    p = net.predict(x)
    print(p)
    print(np.argmax(p))

    t = np.array([0, 0, 1])
    loss = net.loss(x, t)
    print(loss)

    f = lambda w: net.loss(x, t)

    dW = numerical_gradient(f, net.W)
    print(dW)

